package com.czh.springboot04.MyController;

import com.czh.springboot04.entity.MyTest;
import com.czh.springboot04.service.MyTestService;
import com.czh.springboot04.util.R;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@CrossOrigin
@RestController
@RequestMapping("/myTest")
public class MyTestController {
    @Autowired
    private MyTestService myTestService;
    @PostMapping("addMyTest")
    public R addMyTest(@RequestBody MyTest myTest){
        int i=myTestService.addMyTest(myTest);
        if(i> 0 ){
            return R.ok(myTest);
        }else {
            return R.fail("添加失败");
        }
    }
    @PutMapping("updateMyTest")
    public R updateMyTest(@RequestBody MyTest myTest){
        int i=myTestService.updateMyTest(myTest);
        if(i> 0 ){
            return R.ok("修改成功");
        }else {
            return R.fail("失败");
        }
    }
    @DeleteMapping("delete/{id}")
    public R deleteMyTest(@PathVariable("id")int id){
        int i=myTestService.deleteMyTest(id);
        if(i> 0 ){
            return R.ok("删除成功");
        }else {
            return R.fail("失败");
        }
    }
    @GetMapping("findAll")
    public R findAll(@RequestParam(required = false,defaultValue = "1")int pageNum,
                     @RequestParam(required = false,defaultValue = "3")int pageSize,
                     MyTest myTest)
                    {
        PageInfo<MyTest> pageInfo=myTestService.findAll(pageNum,pageSize,myTest);
        return R.ok(pageInfo);
    }
}
